package com.lc.dao.impl;

import com.lc.dao.MyBatisDao;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

/**
 * @author Zhangxiaojie
 * 
 */
@Repository
public class MyBatisDaoImpl<T> extends SqlSessionDaoSupport implements MyBatisDao {
	@Override
	public Integer save(String key, Object entity) throws SQLException {
		return super.getSqlSession().insert(key, entity);
	}

	@Override
	public Integer deleteByKeyword(String key, Object keyword) throws SQLException {
		return super.getSqlSession().delete(key, keyword);
	}

	@Override
	public Integer update(String key, Object entity) throws SQLException {
		return super.getSqlSession().update(key, entity);
	}

	@SuppressWarnings("unchecked")
	@Override
	public T getByKeyword(String key, Object keyword) throws SQLException {
		return (T)super.getSqlSession().selectOne(key, keyword);
	}

	@Override
	public List<T> getByList(String key) throws SQLException {
		return super.getSqlSession().selectList(key);
	}

	@Override
	public List<T> getByList(String key, Object entity) throws SQLException {
		return super.getSqlSession().selectList(key, entity);
	}

	@Override
	public Object getByCallable(String key, Object entity) throws SQLException {
		return super.getSqlSession().selectOne(key, entity);
	}

	
	@Resource
	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate){
		super.setSqlSessionTemplate(sqlSessionTemplate);  
	}

	@Override
	public T getByOne(String key,Date date) throws SQLException {
		return super.getSqlSession().selectOne(key, date);
	}

	@Override
	public T getByKeyword(String key) throws SQLException {
		// TODO Auto-generated method stub
		return super.getSqlSession().selectOne(key);
	}
	
	public Object selectList(String key, Object entity) {
		return super.getSqlSession().selectList(key, entity);
	}

	@Override
	public Object selectList(String key) {
		return super.getSqlSession().selectList(key);
	}
	
	

}
